const express = require('express')
const noteModel = require('../db/model/noteModel')
const ver = require('../middlewares/verifylogin');

let api = express.Router();


api.get('/addnote', ver, (req, res) => {
    res.render('addnote.html')
})

api.get('/content', ver, (req, res) => {
    noteModel.findById({ _id: req.query.id }, (err, data) =>
        res.render('content.html', { data }))
})


api.get('/list', (req, res) => {
    noteModel.find((err, data) => {
        // console.log(data);
        let username = req.session.username || null;
        res.render('list.html', { data, username })
    }

    )
})


api.get('/update', ver, (req, res) => {
    noteModel.findById({ _id: req.query.id }, (err, data) =>
        res.render('update.html', { data })

    )
})


api.get('/center', ver, (req, res) => {
    res.render('center.html')
})
api.get('/logout', ver, (req, res) => {
    req.session.destroy();
    res.render('jump.html', { name: '退出成功' })
})
module.exports = api;